function getCookie(name) {
    var r = document.cookie.match("\\b" + name + "=([^;]*)\\b");
    return r ? r[1] : undefined;
}

$(function() {

    $(".sign_area").submit(function (e) {
        // 阻止表单的默认提交行为
        e.preventDefault();

        // alert("测试代码");
        //获取数据
        var username = $('#username').val();
        var zheng_username = $('#zheng_username').val();
        var sex = $('#sex').val();
        var email = $('#email').val();
        var qq = $('#qq').val();
        var mobil = $('#mobil').val();
        var tel = $('#tel').val();
        // alert(password, password1.);
        if (!username) {
            alert('用户名不能为空!');
            return;
        }


        // 组织参数
        var params = {
            "username": username,
            "zheng_username": zheng_username,
            "sex": sex,
            "email": email,
            "qq": qq,
            "mobil": mobil,
            "tel": tel,
        };

        // TODO: 请求修改用户密码
        $.ajax({
            url: "/usercenter/",
            type: "post",
            data: JSON.stringify(params),
            contentType: "application/json",
            headers: {
                "X-CSRFToken": getCookie("csrf_token")
            },
            success: function (resp) {
                if (resp.code == "0") {
                    // `修改密码`成功
                    alert(resp.errmsg);
                    window.location.reload()  //刷新页面
                }
                else {
                    // `修改密码`失败
                    alert(resp.errmsg);
                }
            }
        })

    })

});